package com.feicheng.lanniao.controller;

import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.feicheng.lanniao.entity.CarRentInfo;
import com.feicheng.lanniao.result.ResultInfo;
import com.feicheng.lanniao.service.ICarRentInfoService;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author feichengTech
 * @since 2021-09-07
 */
@RestController
@RequestMapping("/lanniao-admin/car-rent-info")
public class CarRentInfoController {
	@Autowired
	private ICarRentInfoService icarRentInfoService;
	/**
	 * 查询所有求租车信息 并做分页
	 * @param title 标题
	 * @param details 详情
	 * @param clientId 用户ID
	 * @param currentPage 当前页
	 * @param pageSize 每页分多少条
	 * @return 求租车集合
	 */
	@GetMapping("/page")
	public ResultInfo search(
			String title,
			String details,
			Integer clientId,
			@RequestParam(required = false, defaultValue = "1") Integer currentPage,
			@RequestParam(required = false, defaultValue = "5") Integer pageSize) {
		
		return icarRentInfoService.RentcarList(title,details,clientId,currentPage, pageSize);
	}
	/**
	 * 删除求租车信息
	 * @param crId 主键
	 * @return boolean值
	 */
	@DeleteMapping("/info")
	public ResultInfo del(Integer crId) {
		return icarRentInfoService.deleteRent(crId);
	}
	/**
	 * 查询一条求租车信息
	 * @param crId 主键
	 * @return 对象
	 */
	@GetMapping("/info")
	public ResultInfo select(Integer crId) {
		return icarRentInfoService.selectRentCarById(crId);
	}
	/**
	 * 修改求租车信息
	 * @param carRentInfo 对象
	 * @return boolean值
	 */
	@PutMapping("/info")
	public ResultInfo update(CarRentInfo carRentInfo) {
		return icarRentInfoService.updateRent(carRentInfo);
	}
	/**
	 * 增加求租车信息
	 * @param title 求租车标题
	 * @param details 求租车描述
	 * @param clientId 用户ID
	 * @param tel 发布人电话
	 * @param wxNumber 发布人微信
	 * @return boolean值
	 */

	@PostMapping("/info")
	public ResultInfo add(String tel,String wxNumber,String title,String details,Integer clientId) {
		return icarRentInfoService.addOneRent(tel,wxNumber,title,details,clientId);
	}
}
